<?php
class ControllerArticleFeedback extends ListController {

    protected function heading_title() {
        return "留言列表";
    }
    protected function primary_key_name() {
        return "ID";
    }
    protected function class_path() {
        return "article/feedback";
    }
    protected function model_name() {
        return "model_article_feedback";
    }


    protected function get_list_data(&$ret,$filter_data,$url)
    {

        $total = $this->{$this->model_name()}->getCount($filter_data);
        $ret = $this->{$this->model_name()}->getList($filter_data);

        foreach ($ret as &$result) {
            $result['preview'] = $this->url->link($this->class_path().'/edit', 'token=' . $this->session->data['token']  . '&'.$this->primary_key_name(). '=' . $result['ID'] . $url, 'SSL');

        }
        return $total;
    }


    protected function get_form_data(&$data){
        $item = null;
        if (isset($this->request->get[$this->primary_key_name()]) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
            $comments = $this->{$this->model_name()}->getItem($this->request->get[$this->primary_key_name()]);

            $table = "<table class='table table-bordered table-hover''>";
            $table .= "<thead>";
            $table .= "<tr>";
            $table .= "  <td class='text-left'><a>用户</a></td>";
			 $table .= "      <td class='text-left' style='width:60%'><a>内容</a></td>";
            $table .= "      <td class='text-left'><a>发送时间</a></td>";
           
            $table .= "      <td class='text-left'><a>操作</a></td>";
            $table .= "</tr> </thead><tbody>";

            foreach ($comments as $comment) {
                $table .= "<tr>";
                $table .= "<td class='text-left'><img style='width:30px;height:30px;' src='{$comment['image']}' /> {$comment['comment_author']}</td>";
                 $table .= "<td class='text-left' style='width:60%'>{$comment['comment_content']}</td>";
                $table .= "<td class='text-left'>{$comment['comment_date']}</td>";
               
                if ((int)$comment['user_id'] !=(int)$comment['comment_type'] ){
                    $table .= "<td class='text-left'></td>";
                }
                else{
                    $table .= "<td class='text-left'><a onclick=\"comment({$comment['comment_type']})\" title=\"回复\"><i class=\"fa \">回复</i></a></td>";
                }

                $table .= "</tr>";


            }

            $table .= "</tbody></table>";
            $data['extra']['post_comments'] = $table;
        }

    }
    public function comment()
    {

        $this->load->model($this->class_path());
        $this->model_article_feedback->comment($this->user->getUserName(),$this->request->get['customer_id'],$this->user->getId(),$this->request->get['message']);

    }

    protected function validateForm() {

        return !$this->error;
    }

    protected function validateDelete() {

        return !$this->error;
    }
}